---
- name: Apt provisioning
  hosts: nodes
  become: true
  tasks:
    - name: apt update
      ansible.builtin.apt:
        update_cache: yes
    - name: install packages
      ansible.builtin.apt:
        name:
          - ca-certificates
          - curl
          - gnupg
          - lsb-release
          - python3
          - python3-pip
        state: present
    - name: Add Docker GPG apt Key
      ansible.builtin.apt_key:
        url: https://download.docker.com/linux/ubuntu/gpg
        state: present
    - name: Add Docker Repository
      apt_repository:
        repo: deb https://download.docker.com/linux/ubuntu bionic stable
        state: present
    - name: apt update after add repo
      ansible.builtin.apt:
        update_cache: yes
    - name: install Docker
      ansible.builtin.apt:
        name:
          - docker-ce
          - docker-ce-cli
          - containerd.io
        state: present
    - name: Install Docker-compose
      ansible.builtin.get_url:
        url: https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-linux-{{lookup('pipe', 'uname -m')}}
        dest: /usr/local/bin/docker-compose
        mode: +x
    - name: Start docker daemon
      ansible.builtin.systemd:
        name: docker
        state: started
    - name: Install docker python module
      ansible.builtin.pip:
        name:
          - docker
          - docker-compose
    - name: Add Ubuntu user to docker group
      ansible.builtin.user:
        name: ubuntu
        groups: docker
        append: yes
    - name: Reconnect to server session
      ansible.builtin.meta: reset_connection



